const axios = require('axios')

axios.defaults.headers.post['Content-Type'] = 'application/json';

const instance = axios.create({
	timeout: 60000,
});

module.exports = {

	taskListApi(params) {
		return getDataJSON('/cms/task/list', params)
	},

	taskMenuApi() {
		return getDataJSON('/cms/task/menu')
	},

	isTaskRunningApi(params) {
		return getDataJSON('/cms/task/isrunning', params)
	},

	startTaskApi(params) {
		return getDataJSON('/cms/task/start', params)
	},

	dbListApi(params) {
		return getDataJSON('/cms/db/list', params)
	},
}

// 使用axios data为服务器返回值
function getDataJSON(url, params) {
	return new Promise((resolve, rejcet) => {
		instance.post(url, params).then(result => {
			let data = result.data
			try {
				data = JSON.parse(data)
			} catch (e) {

			}
			console.log('data', data)
			resolve(data)
		}).catch(err => {
			rejcet(err)
		})
	})
}